package Interface;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Hashtable;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import Entities.Identification;
import Language.Language;

public class index extends JFrame implements ActionListener {
	
	protected JLabel lblLogin;
	protected JLabel lblPassword;
	protected JTextField txtLogin;
	protected JPasswordField txtPassword;
	protected JButton btnIdentification;
	protected JButton btnClose;
	protected JPanel pnlConteneur_main;
	
	public index(String title) {
		super(title);	
		
		pnlConteneur_main = (JPanel)this.getContentPane(); 
		pnlConteneur_main.setLayout(new GridLayout(3,2));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		lblLogin = new JLabel(Language.getAnInternationalizeString("LoginFrame_lblLogin"),JLabel.LEFT);
		txtLogin = new JTextField();
		lblPassword = new JLabel(Language.getAnInternationalizeString("LoginFrame_lblPassword"),JLabel.LEFT);
		txtPassword = new JPasswordField();
		
		btnIdentification = new JButton(Language.getAnInternationalizeString("LoginFrame_btnConnection"));
		btnClose = new JButton(Language.getAnInternationalizeString("LoginFrame_btnQuitter"));
		
		// Ajout des label et textfield
		pnlConteneur_main.add(lblLogin);
		pnlConteneur_main.add(txtLogin);
		pnlConteneur_main.add(lblPassword);
		pnlConteneur_main.add(txtPassword);
		
		// Ajout des boutons
		pnlConteneur_main.add(btnClose);
		pnlConteneur_main.add(btnIdentification);	
		
		// Action lies aux boutons
		btnIdentification.addActionListener(this);
		btnClose.addActionListener(this);
		
		// Taille de la fenetre
		this.setSize(350,127); 
		this.setVisible(true);
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation((screen.width - this.getSize().width)/2,(screen.height - this.getSize().height)/2);
	}
	
	 public void actionPerformed(ActionEvent evt)
	 { 
		 if(evt.getSource() == btnIdentification)
		 {
			 Hashtable recap = new Hashtable();
			 recap.put("login", txtLogin.getText()); 
			 recap.put("password", txtPassword.getText());
			 Identification identification = new Identification(recap, this);
		 }
		 else 
		 {
			 this.dispose();
		 }
	 }
		 
	public static void main(String[] args) {
		// Initialisation du langage
		Language.initializeLanguage();
		
		index intro = new index(Language.getAnInternationalizeString("LoginFrame_Title"));
	}
}
